<?php
require('conexion.php');
//error_reporting(0);
session_start();
if(isset($_POST['idven'])){
$idven=$_POST['idven'];
$conn->Execute('set lc_monetary=english');
$rs=$conn->Execute("select id_sucursal,id_empleado from ventas where id_venta='$idven'");
$idemp=$rs->fields[1];
$idsuc=$rs->fields[0];
if($rs->fields[1]==''){
die( 'la venta no existe');
}
$sql = "select genera_ticket($idven,$idsuc,$idemp)";
$rs = $conn->Execute($sql);
?>
<style>
table{
	text-align:center;
	}
</style>
<table border="1">
<tr>
<th colspan="6">Datos de la empresa</th>
</tr>
<tr>
<td>Sucursal</td><td colspan="4">Direccion</td><td>Telefono</td>
</tr>

<?php
$sql = "select * from sucursal";
$rs = $conn->Execute($sql);
?>
        <tr>
        		<td><?php echo $rs->fields[0];?></td>
                <td><?php echo $rs->fields[1];?></td>
                <td><?php echo $rs->fields[2];?></td>
                <td><?php echo $rs->fields[3];?></td>
				<td><?php echo $rs->fields[4];?></td>
                <td><?php echo $rs->fields[5];?></td>
                
        </tr>
</table>
         <br>
 <table border="1">
        <tr>
        <th colspan="4">Datos del empleado</th>
        </tr>
        <tr>
        <td colspan="2">Empleado</td>
        </tr>
        <tr>
        		<td><?php echo $rs->fields[6];?></td>
                <td><?php echo $rs->fields[7];?></td> 

		</tr>

	</table>
    <br>	
<table border="1">
<tr>
<th colspan="4">Datos de la venta</th>
</tr>
<tr>
<td>Producto</td><td>Fecha</td><td>Precio unitario</td><td>Cargo</td>
</tr>
<?php
$sql = "select * from ventas";
$rs = $conn->Execute($sql);
	foreach($rs as $i=>$k):?>
		<tr>
				<td><?php echo $k[0];?></td>
                <td><?php echo $k[1];?></td>
                <td><?php echo $k[2];?></td>
                <td><?php echo $k[3];?></td>
        </tr>
		<?php endforeach;?>
<tr>
<?
$sql = "select cerrar_venta($idven)";
$rs = $conn->Execute($sql);
?>
<td colspan="3">Gracias x su compra</td>

</tr>
</table>
<?
$conn->Execute('drop table tventa');
$conn->Execute('drop table tsuc');	
}
else{
?>
	<form action="Cventa.php" method="post">
Id venta:<?php
$rs=$conn->Execute('select id_venta,id_venta from ventas order by id_venta asc');
echo $rs->getMenu('idven');
?>
<input type="submit" name="ingresar" value="Ver ticket">
    </form>
    <a href="login.php">Login</a><br>
    <a href="Mventa.php">Modificar venta</a><br>
	<a href="productos.php">Ver productos</a><br>
	<a href="empleados.php">Ver empleados</a><br>
	<a href="cierre.php">Cerrar sesion</a>

<?php 

}?>